package cn.alex.sso.project.controller;

import cn.alex.sso.framework.annotations.OperatLog;
import cn.alex.sso.framework.constant.ModuleConstant;
import cn.alex.sso.framework.core.Result;
import cn.alex.sso.project.entity.SysClientAllow;
import cn.alex.sso.project.service.SysClientAllowService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 应用授权
 *
 * @author Alex
 * @date 2024/10/12 01:57
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/client/allow")
public class SysClientAllowController {
    private final SysClientAllowService baseService;

    /**
     * 获取列表
     */
    @GetMapping("/getList")
    public Result getList(Long clientId) {
        return Result.ok(baseService.getListByClientId(new ArrayList<Long>() {{
            add(clientId);
        }}));
    }

    /**
     * 保存
     */
    @PostMapping("/{clientId}")
    @OperatLog(module = ModuleConstant.ROLE, action = "授权")
    public Result change(@PathVariable Long clientId, @RequestBody List<SysClientAllow> clientAllowList) {
        baseService.change(clientId, clientAllowList);
        return Result.ok();
    }
}
